﻿// ==========================================================================
// HomeViewModel.cs
// Silverlight Shapes Library
// ==========================================================================
// Copyright (c) Silverlight Shapes Development Group
// All rights reserved.
// ==========================================================================

using System.ComponentModel.Composition;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using SD.Samples.Configuration;
using SD.Samples.Messages;

namespace SD.Samples.Views
{
    /// <summary>
    /// Defines the view model for the Home page.
    /// </summary>
    [Export]
    public class HomeViewModel
    {
        #region Properties

        /// <summary>
        /// Gets or sets the samples configuration for this application.
        /// </summary>
        /// <value>The samples configuration.</value>
        public SampleRepository Samples { get; private set; }

        #endregion

        #region Commands

        private RelayCommand<string> _navigateToSampleCommand;
        /// <summary>
        /// Gets the command to navigate to the sample that is specified as command parameter.
        /// </summary>
        /// <value>The command to navigate to the sample that is specified as command parameter.</value>
        public RelayCommand<string> NavigateToSampleCommand
        {
            get
            {
                if (_navigateToSampleCommand == null)
                {
                    _navigateToSampleCommand = new RelayCommand<string>(
                        x =>
                        {
                            Messenger.Default.Send(new NavigateToSampleMessage(x));
                        });
                }

                return _navigateToSampleCommand;
            }
        }

        #endregion

        #region Constructors

        /// <summary>
        /// Initializes a new instance of the <see cref="HomeViewModel"/> class.
        /// </summary>
        public HomeViewModel()
        {
            Samples = ApplicationSamples.Default;
        }

        #endregion
    }
}
